<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>用户管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {

		});

		function  showTable(id1,id2){
			var tb=document.getElementById(id1);
			if(tb.style.display=='none')
				tb.style.display='';
			else tb.style.display='none';
			tb=document.getElementById(id2);
			if(tb.style.display=='none')
				tb.style.display='';
			else tb.style.display='none';
		}

		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		function showRecharge(userid){
			$('#userid').select2('val', userid);
			$("#rechargeModal").modal("show");
		}

		//充值
		function onRecharge(){
			var userid = $("#userid").val();
			var changeType = $("#changeType").val();
			var accAmount = $("#accAmount").val();
			var remark = $("#remark").val();
			if(changeType == null || changeType==''){
				alertx("请选择充值方式");
				return;
			}

			if(!digits(accAmount)){
				alertx("请输入正确数字");
				return;
			}

			remark = encodeURI(encodeURI(remark));

			$.ajax({
				type: 'POST',
				url: "${ctx}/account/baseAccount/ajaxRecharge?accAmount="+accAmount+"&changeType="+changeType+"&userid="+userid+"&accType=sms&remark="+remark,
				success: function(result){
					alertx(result);
					page();
				},
				error: function(){
					alertx("系统错误");
				}
			});


		}

		function digits(nubmer){
			var re =  /^[1-9]+[0-9]*]*$/; //判断正整数 /^[1-9]+[0-9]*]*$/
			if(re.test(nubmer))return true;
			return false;
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/sys/user/costomerlist">用户列表</a></li>
		<shiro:hasPermission name="sys:user:edit"><li><a href="${ctx}/sys/user/customerform">用户添加</a></li></shiro:hasPermission>
	</ul>
	<form:form id="searchForm" modelAttribute="user" action="${ctx}/sys/user/customerlist" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<ul class="ul-form">
			<li><label>姓名：</label>
				<form:input path="name" htmlEscape="false" maxlength="100" class="input-medium"/>
			</li>
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/></li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	<sys:message content="${message}"/>
	<input type="button" value="显示/隐藏客户详细信息" onClick="showTable('contentTable','detailTable')"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>id</th>
				<th>公司简称</th>
				<th>余额</th>
				<th>价格</th>
				<th>开户时间</th>
				<th>行业</th>
				<th>商务</th>
				<shiro:hasPermission name="sys:user:edit"><th>操作</th></shiro:hasPermission>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="user">
			<tr>
				<td>
						${user.id}
				</td>
				<td>
						${user.companyShortname}
				</td>
				<td>
						${user.amount}
				</td>
				<td>
						${user.price}
				</td>
				<td>
					<fmt:formatDate value="${user.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
				</td>
				<td>
						${user.industry}
				</td>
				<td>
						${user.business}
				</td>

				<shiro:hasPermission name="sys:user:edit"><td>
    				<a href="${ctx}/sys/user/customerform?id=${user.id}">修改</a>
					<a href="${ctx}/sys/user/deletecustomer?id=${user.id}" onclick="return confirmx('确认要删除该用户吗？', this.href)">删除</a>
					<c:if test="${ user.loginFlag == 1 }">
						<a href="${ctx}/sys/user/freezecustomer?id=${user.id}" onclick="return confirmx('确认要冻结该用户吗？', this.href)">冻结</a>
					</c:if>
					<c:if test="${ user.loginFlag == 0 }">
						<a href="${ctx}/sys/user/freezecustomer?id=${user.id}" onclick="return confirmx('确认要解冻该用户吗？', this.href)">解冻</a>
					</c:if>
					<a href="javascript:showRecharge(${user.id});">充值</a>
				</td></shiro:hasPermission>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<table id="detailTable" style="display:none;" class="table table-striped table-bordered table-condensed">
		<thead>
		<tr>
			<th>用户名</th>
			<th>价格</th>
			<th>用户类型</th>
			<th>计费方式</th>
			<th>密码</th>
			<th>Ip限制</th>
			<th>公司全称</th>
			<th>公司地址</th>
			<th>开票金额</th>
			<th>未开票金额</th>
			<th>行业</th>
			<th>用量</th>
			<th>联系人1</th>
			<th>电话1</th>
			<th>联系人2</th>
			<th>电话2</th>
			<th>联系人3</th>
			<th>电话3</th>

			<shiro:hasPermission name="sys:user:edit"><th>操作</th></shiro:hasPermission>
		</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="user">
			<tr>
				<td>
						${user.name}
				</td>
				<td>
						${user.price}
				</td>
				<td>
						${user.userType}
				</td>
				<td>
						${user.billMethod}
				</td>
				<td>
						${user.password}
				</td>
				<td>
						${user.interfaceIp}
				</td>
				<td>
						${user.companyName}
				</td>
				<td>
						${user.companyAddress}
				</td>
				<td>
						${user.totalInvoiceAmount}
				</td>
				<td>
						${user.invoiceAmount}
				</td>
				<td>
						${user.industry}
				</td>
				<td>
						${user.dosage}
				</td>
				<td>
						${user.contact1}
				</td>
				<td>
						${user.phone1}
				</td>
				<td>
						${user.contact2}
				</td>
				<td>
						${user.phone2}
				</td>
				<td>
						${user.contact3}
				</td>
				<td>
						${user.phone3}
				</td>

				<shiro:hasPermission name="sys:user:edit"><td>
					<a href="${ctx}/sys/user/customerform?id=${user.id}">修改</a>
					<a href="${ctx}/sys/user/deletecustomer?id=${user.id}" onclick="return confirmx('确认要删除该用户吗？', this.href)">删除</a>
					<c:if test="${ user.loginFlag == 1 }">
						<a href="${ctx}/sys/user/freezecustomer?id=${user.id}" onclick="return confirmx('确认要冻结该用户吗？', this.href)">冻结</a>
					</c:if>
					<c:if test="${ user.loginFlag == 0 }">
						<a href="${ctx}/sys/user/freezecustomer?id=${user.id}" onclick="return confirmx('确认要解冻该用户吗？', this.href)">解冻</a>
					</c:if>
					<a href="javascript:showRecharge(${user.id});">充值</a>
				</td></shiro:hasPermission>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>

	<!-- 充值modal -->
	<div class="modal fade" style="display:none;" id="rechargeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close"
							data-dismiss="modal" aria-hidden="true">
						&times;
					</button>
					<h4 class="modal-title" id="myModalLabel">
						充值
					</h4>
				</div>
				<div class="modal-body">
					<form id="rechargeForm" class="form-horizontal">
						<div class="control-group">
							<div class="controls1">
								<div class="control-group">
									<label class="control-label">用户：</label>
									<div class="controls">
										<select id="userid" name="id" class="input-xlarge required">
											<c:forEach items="${fns:getUserList('lower')}" var="item">
												<option value="${item.value }">${item.label}</option>
											</c:forEach>
										</select>
										<span class="help-inline"><font color="red">*</font> </span>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">充值方式：</label>
									<div class="controls">
										<select id="changeType" name="changeType" class="input-xlarge required">
											<option value="">请选择</option>
											<option value="CZ00">充值转入</option>
											<option value="CZ01">手动返充</option>
											<option value="XF01">手动扣款</option>
										</select>
										<span class="help-inline"><font color="red">*</font> </span>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">充值额度：</label>
									<div class="controls">
										<input type="text" id="accAmount" name="accAmount" htmlEscape="false" maxlength="8" class="input-xlarge"/>
										<span class="help-inline"><font color="red">*</font> </span>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">备注：</label>
									<div class="controls">
										<input type="text" id="remark" name="remark" htmlEscape="false" maxlength="100" class="input-xlarge"/>
									</div>
								</div>
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<input id="btnSubmit1" class="btn btn-primary" type="button" value="充值" onclick="javascript:onRecharge();"/>
					<input id="btnSubmit2" class="btn btn-primary" type="button" value="关 闭" data-dismiss="modal" aria-hidden="true"/>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal -->
	</div>
	<!-- END -->

</body>
</html>